<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *售后列表
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
if($_RQ['op']=='list'){
	$tabs=array(
		array('op'=>'list','title'=>'用户列表'),
	);
}else{
	$tabs=array(
		array('op'=>'fromclass','title'=>'用户列表'),
	);
}
$tabs[]=array('action'=>'xuesheng.add','title'=>'录入老用户');
$batch=array(
	array('type'=>'api','url'=>'/xuesheng.danganlist/export/','title'=>'导出售后档案')
);
//售后列表
if($_RQ['op']=='list' || $_RQ['op']=='fromclass'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$return['params']=array();
	$params=array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']);
	if($_RQ['status']!='all' && $_RQ['status']){
		$params['status']=intval($_RQ['status']);
	}
	if($_RQ['id'] && $_RQ['op']=='fromclass'){
		$params['classid']=intval($_RQ['id']);
		$return['params']['classid']=$_RQ['id'];
		$this->session('classid',$params['classid']);
		$this->model('uplog')->upclasskaoqing_log($params['classid']);
	}
	if($_RQ['classid']){
		$params['classid']=intval($_RQ['classid']);
		$return['params']['classid']=$_RQ['classid'];
	}elseif($this->session('classid')){
		$params['classid']=$this->session('classid');
		$return['params']['classid']=$this->session('classid');
	}
	$return['params']['status']=$_RQ['status'];
	if(!empty($_RQ['title'])){
		$params['title like']='%'.$_RQ['title'].'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(!empty($_RQ['mobile'])){
		$params['mobile']=$_RQ['mobile'];
		$return['params']['mobile']=$_RQ['mobile'];
	}
	if(!empty($_RQ['fromstoreid'])){
		$params['fromstoreid']=$_RQ['fromstoreid'];
		$return['params']['fromstoreid']=$_RQ['fromstoreid'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = $_RQ['psize']?:10;
	if($_RQ['psize']){
		$return['params']['psize']=$_RQ['psize'];
	}
	$list=pdo_getslice('jy_yxw_xuesheng',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['member']=$this->model('xuesheng')->member_show($item['id']);
			if($item['danganimage1'] && $item['danganimage2']){
				$item['isdangan']='未上传档案';
			}
			if(!$item['danganimage1'] || !$item['danganimage2']){
				$item['isdangan']='已上传档案';
			}
			if(!$item['danganimage1'] && !$item['danganimage2']){
				$item['isdangan']='已上传部分档案';
			}
			$item['createtime']=date('Y-m-d',$item['createtime']);
			$member=pdo_get('jy_yxw_member',array('id'=>$item['memberid'],'uniacid'=>$_SESSION['uniacid']));
			$item=array_merge($member,$item);
			$infee_log=pdo_get('jy_yxw_infee_log',array('type'=>1,'status'=>1,'memberid'=>$item['memberid'],'uniacid'=>$_SESSION['uniacid']));
			$item['pay_type']=$infee_log['pay_type'];
			$item['fee']=$infee_log['fee']?:$item['baofee'];
			$item['worker6']=pdo_getcolumn('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['worker6id']),'title');
			$item['set']='/xuesheng.danganlist/set/id='.$item['id'];
			$item['classtitle']=pdo_getcolumn('jy_yxw_class',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['classid']),'title');
			$item['xuelititle']=$this->xueli_type[$item['xueli']];
			$item['pay_typetitle']=$item['pay_typetitle']?:$this->pay_types[$infee_log['pay_type']];
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	//页面显示设置
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'export'=>'export',
		'list'=>array('data'=>'list','del_message'=>'确认删除该售后吗？','total'=>$total,'psize'=>$psize,'del_op'=>'del','del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'fromstoreid','title'=>'招生门店','type'=>'select2','options'=>'stores'),
			array('name'=>'member','title'=>'用户信息','type'=>'member'),
			array('name'=>'sn','title'=>'编号','type'=>'string'),
			array('name'=>'classtitle','title'=>'售后群','type'=>'string'),
			array('type'=>'string','title'=>'身份证','name'=>'cardno'),
			array('type'=>'string','title'=>'学历','name'=>'xuelititle'),
			array('type'=>'string','title'=>'单费','name'=>'fee'),
			array('name'=>'pay_typetitle','title'=>'缴费方式','type'=>'string'),
			array('name'=>'worker6','title'=>'销售员员','type'=>'string'),
			array('name'=>'isdangan','title'=>'上传情况','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radio2','options'=>'status'),
			array('name'=>'createtime','title'=>'成交日期','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal','action'=>'/xuesheng.fangtan/add/','title'=>'访谈'),
			array('type'=>'href','action'=>'/xuesheng.danganlist/lookdanganinfo/','title'=>'档案'),
			array('type'=>'href','action'=>'/xuesheng.danganlist/set/','title'=>'管理'),
		),'batch'=>$batch),
		'search'=>array(
			array('type'=>'string','width'=>'15','title'=>'手机号','name'=>'mobile','help'=>''),
			array('type'=>'string','width'=>'15','title'=>'售后名称','name'=>'title','help'=>''),
			array('name'=>'status','width'=>'15','title'=>'状态','type'=>'radio','options'=>'status'),
			//array('name'=>'classid','width'=>'15','title'=>'售后群','type'=>'select','options'=>'class'),
			array('name'=>'fromstoreid','width'=>'15','title'=>'招生门店','type'=>'select','options'=>'stores'),
		),
	);
	$return['stores']=$this->getall('store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['class']=$this->getall('class',array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
	//$return['workers']=$this->getall('worker',array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
	$return['status']=$this->xuesheng_status;
	$return['jibie_type']=$this->member_jibie_type;
	$return['xueli_type']=$this->xueli_type;
	$return['pay_types']=$this->pay_types;
	$return['isdangan']=array('未上传档案','已上传档案','已上传部分档案');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='danganimage'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=$post['id'];
		$dangan=array(
			'pay_type'=>intval($post['pay_type']),
			'fen_file'=>trim($post['fen_file']),
			'danganimage1'=>trim($post['danganimage1']),
			'danganimage2'=>trim($post['danganimage2']),
			'px_file'=>trim($post['px_file']),
			'rx_file'=>trim($post['rx_file']),
			'jj_file'=>trim($post['jj_file']),
		);
		$this->model('uplog')->updangan($dangan,intval($post['memberid']));
		exi('操作成功！','','/xuesheng.danganlist//');
	}
	if($_RQ['id']){
		$memberid=pdo_getcolumn('jy_yxw_xuesheng',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']),'memberid');
		$item=pdo_get('jy_yxw_dangan',array('uniacid'=>$_SESSION['uniacid'],'memberid'=>$memberid));
	}else{
		exi('请先选择售后','error');
	}
	$return['item']=$item;	
	$htmls=array(
		'type'=>'edit',
		'desc'=>'用户档案资料',
	);
	$htmls['edit']=array(
		array('type'=>'image','title'=>'用户档案照片A面','name'=>'danganimage1'),
		array('type'=>'image','title'=>'用户档案照片B面','name'=>'danganimage2'),
		array('type'=>'image','title'=>'现金分期承诺书','name'=>'fen_file','show'=>array('pay_type'=>1)),
		array('type'=>'image','title'=>'贷款分期承诺书','name'=>'fen_file','show'=>array('pay_type'=>array(2,3))),
		array('type'=>'image','title'=>'用户培训协议','name'=>'px_file'),
		array('type'=>'image','title'=>'用户入学协议','name'=>'rx_file'),
		array('type'=>'image','title'=>'用户交接表','name'=>'jj_file'),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='lookdanganimage'){
	if($_RQ['id']){
		$memberid=pdo_getcolumn('jy_yxw_xuesheng',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']),'memberid');
		$item=pdo_get('jy_yxw_dangan',array('uniacid'=>$_SESSION['uniacid'],'memberid'=>$memberid));
	}else{
		exi('请先选择售后','error');
	}
	$return['item']=$item;	
	$htmls=array(
		'type'=>'look',
		'desc'=>'查看档案资料',
	);
	$htmls['look']=array(
		array('type'=>'image','title'=>'用户档案照片A面','name'=>'danganimage1'),
		array('type'=>'image','title'=>'用户档案照片B面','name'=>'danganimage2'),
		array('type'=>'image','title'=>'现金分期承诺书','name'=>'fen_file','show'=>array('pay_type'=>1)),
		array('type'=>'image','title'=>'贷款分期承诺书','name'=>'fen_file','show'=>array('pay_type'=>array(2,3))),
		array('type'=>'image','title'=>'用户培训协议','name'=>'px_file'),
		array('type'=>'image','title'=>'用户入学协议','name'=>'rx_file'),
		array('type'=>'image','title'=>'用户成交交接表','name'=>'jj_file'),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='lookdanganinfo'){
	if($_RQ['id']){
		$item=pdo_get('jy_yxw_xuesheng',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
		$item['createtime']=date('Y-m-d',$item['createtime']);
		$member=pdo_get('jy_yxw_member',array('id'=>$item['memberid'],'uniacid'=>$_SESSION['uniacid']));
		$item=array_merge($member,$item);
		$dangan=pdo_get('jy_yxw_dangan',array('uniacid'=>$_SESSION['uniacid'],'memberid'=>$item['memberid']));
		$dangan['fen_file']=json_decode($dangan['fen_file'],true);
		$dangan['danganimage1']=json_decode($dangan['danganimage1'],true);
		$dangan['danganimage2']=json_decode($dangan['danganimage2'],true);
		$dangan['px_file']=json_decode($dangan['px_file'],true);
		$dangan['rx_file']=json_decode($dangan['rx_file'],true);
		$dangan['jj_file']=json_decode($dangan['jj_file'],true);
		$item=array_merge($dangan,$item);
		$infee_log=pdo_get('jy_yxw_infee_log',array('memberid'=>$item['memberid'],'uniacid'=>$_SESSION['uniacid']));
		$item['pay_type']=$infee_log['pay_type'];
		$item['fee']=$infee_log['fee'];
		$item['worker6']=pdo_getcolumn('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['worker6id']),'title');
	}else{
		exi('请先选择售后','error');
	}
	$item['wj1']=pdo_count('jy_yxw_weiji_log',array('type'=>1,'xueshengid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),'id');
	$item['wj2']=pdo_count('jy_yxw_weiji_log',array('type'=>2,'xueshengid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),'id');
	$item['wj3']=pdo_count('jy_yxw_weiji_log',array('type'=>3,'xueshengid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),'id');
	$item['goodnum']=pdo_count('jy_yxw_kaoqing_log',array('type'=>0,'xueshengid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),'id');
	$item['cdnum']=pdo_count('jy_yxw_kaoqing_log',array('type'=>1,'xueshengid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),'id');
	$item['bjnum']=pdo_count('jy_yxw_kaoqing_log',array('type'=>2,'xueshengid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),'id');
	$item['sjnum']=pdo_count('jy_yxw_kaoqing_log',array('type'=>3,'xueshengid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),'id');
	$item['kknum']=pdo_count('jy_yxw_kaoqing_log',array('type'=>4,'xueshengid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),'id');
	$htmls=array(
		'type'=>'look',
		'look_tab'=>true,
		'looks'=>array(
			array(
				'title'=>'用户信息',
				'list'=>array(
					array('name'=>'title','title'=>'个人资料','type'=>'help','help'=>''),
					array('name'=>'title','title'=>'售后姓名','type'=>'string'),
					array('type'=>'string','title'=>'身份证','name'=>'cardno'),
					array('name'=>'sn','title'=>'编号','type'=>'string'),
					array('name'=>'logo','title'=>'相片','type'=>'image'),
					array('name'=>'title','title'=>'个人档案','type'=>'help','help'=>''),
					array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
					array('name'=>'classid','title'=>'售后群','type'=>'select','options'=>'class'),
					array('name'=>'createtime','title'=>'成交日期','type'=>'string'),
					array('type'=>'radio','title'=>'学历','name'=>'xueli','options'=>'xueli_type'),
					array('type'=>'string','title'=>'单费','name'=>'fee'),
					array('type'=>'radio','title'=>'缴费方式','name'=>'pay_type','options'=>'pay_types'),
					array('name'=>'worker6','title'=>'销售员员','type'=>'string'),
					array('name'=>'title','title'=>'学习情况','type'=>'help','help'=>''),
					array('type'=>'string','title'=>'普通违纪次数','name'=>'wj1'),
					array('type'=>'string','title'=>'中等违纪次数','name'=>'wj2'),
					array('type'=>'string','title'=>'严重违纪次数','name'=>'wj3'),
					array('type'=>'string','title'=>'正常考勤天数','name'=>'goodnum'),
					array('type'=>'string','title'=>'迟到次数','name'=>'cdnum'),
					array('type'=>'string','title'=>'病假次数','name'=>'bjnum'),
					array('type'=>'string','title'=>'事假次数','name'=>'sjnum'),
					array('type'=>'string','title'=>'旷课次数','name'=>'kknum'),
				)
			),
		   array(
				'title'=>'档案资料',
				'list'=>array(
					array('type'=>'images','title'=>'用户档案照片A面','name'=>'danganimage1'),
					array('type'=>'images','title'=>'用户档案照片B面','name'=>'danganimage2'),
					array('type'=>'images','title'=>'现金分期承诺书','name'=>'fen_file','show'=>array('pay_type'=>1)),
					array('type'=>'images','title'=>'贷款分期承诺书','name'=>'fen_file','show'=>array('pay_type'=>array(2,3))),
					array('type'=>'images','title'=>'用户培训协议','name'=>'px_file'),
					array('type'=>'images','title'=>'用户入学协议','name'=>'rx_file'),
					array('type'=>'images','title'=>'用户成交交接表','name'=>'jj_file'),
				)
			),
		)
	);
	$fangtans=$this->getall('fangtan_log',array('xueshengid'=>$item['id'],'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
	$fangtan_type=$this->fangtan_type;
	$htmls['looks'][0]['list'][]=array('name'=>'title','title'=>'访谈情况','type'=>'help','help'=>'');
	foreach($fangtans as $k=>$fv){
		$title=date('Y-m-d',$fv['createtime']).$fangtan_type[$fv['type']].'情况';
		$item['ftmsg'.$k]=$fv['remark'];
		$htmls['looks'][0]['list'][]=array('type'=>'string_log','title'=>$title,'name'=>'ftmsg'.$k);
	}
	$jiuyes=$this->getall('jiuye_log',array('xueshengid'=>$item['id'],'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
	$htmls['looks'][0]['list'][]=array('name'=>'title','title'=>'反馈情况','type'=>'help','help'=>'');
	foreach($jiuyes as $k=>$jv){
		if(!$jv['jobtype']){
			$title=date('Y-m-d',$jv['createtime']).$job_type[$jv['jobtype']].'情况';
			$msg='累计面试['.$jv['miannum'].']次,累计拿到offer['.$jv['offernum'].']次。';
		}else{
			$title=$jv['jobtime'].'反馈';
			$msg='公司['.$jv['jobgs'].'],反馈岗位['.$jv['jobgw'].'],试用期薪资['.$jv['jobfee1'].'],转正薪资['.$jv['jobfee2'].']';
		}
		$item['jobmsg'.$k]=$msg;
		$htmls['looks'][0]['list'][]=array('type'=>'string_log','title'=>$title,'name'=>'jobmsg'.$k);
	}
	$return['class']=$this->getall('class',array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['status']=$this->xuesheng_status;
	$return['jibie_type']=$this->member_jibie_type;
	$return['xueli_type']=$this->xueli_type;
	$return['pay_types']=$this->pay_types;
	$return['item']=$item;	
	$return['isdangan']=array('未上传档案','已上传档案','已上传部分档案');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='set'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=$post['id'];
		$isadd=pdo_get('jy_yxw_xuesheng_log',array('status'=>array(0,2),'uniacid'=>$_SESSION['uniacid'],'xueshengid'=>$id));
		if($isadd){
			exi('该售后已经存在待审核事项！要等完结才能再次申请！','error');
		}
		if($post['setstatus']==1 && (!$post['tostoreid'] || !$post['toclassid'])){
			exi('请先选择门店和售后群！','error');
		}
		if($post['setstatus']==2 && !$post['toclassid']){
			exi('请先选择售后群！','error');
		}
		$update=array('setstatus'=>$post['setstatus']);
		pdo_update('jy_yxw_xuesheng',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		$this->model('uplog')->upxueshenglog($post);
		exi('操作成功！','','/xuesheng.danganlist//status=all');
	}
	if($_RQ['id']){
		$item=pdo_get('jy_yxw_xuesheng',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	}else{
		exi('请先选择售后','error');
	}
	$item['storetitle']=pdo_getcolumn('jy_yxw_store',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['storeid']),'title');
	$item['classtitle']=pdo_getcolumn('jy_yxw_class',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['classid']),'title');
	$item['keshi']=pdo_getcolumn('jy_yxw_class',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['classid']),'keshi');
	$item['kechengid']=pdo_getcolumn('jy_yxw_class',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['classid']),'kechengid');
	$item['kecheng']=pdo_getcolumn('jy_yxw_kecheng',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['kechengid']),'title');
	$item['kechengprice']=pdo_getcolumn('jy_yxw_kecheng',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['kechengid']),'price');
	$item['baomingday']=date('Y-m-d',$item['createtime']);
	$item['workername']=pdo_getcolumn('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_SESSION['workerid']),'title');
	$item['setday']=date('Y-m-d');
	$item['baofee']=pdo_getcolumn('jy_yxw_infee_log',array('type'=>1,'status'=>1,'memberid'=>$item['memberid'],'uniacid'=>$_SESSION['uniacid']),'fee');
	$item['iskeshi']=pdo_count('jy_yxw_kaoqing_log',array('classid'=>$item['classid'],'xueshengid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']));
	$item['lastkeshi']=$item['keshi']-$item['iskeshi'];
	$item['keshi']=$item['keshi']?:1;
	$item['onefee']=intval($item['baofee']/$item['keshi']);
	$item['lastfee']=intval($item['baofee']-$item['onefee']*$item['iskeshi']);
	$return['item']=$item;	
	$htmls=array(
		'type'=>'edit',
		'title'=>'管理事项',
	);
	$htmls['edit']=array(
		array('type'=>'title','title'=>'选择管理事项'),
		array('type'=>'radio','title'=>'管理事项','name'=>'setstatus','options'=>'setstatus'),
		array('type'=>'title','title'=>'售后当前信息'),
		array('type'=>'string_two2','title1'=>'售后姓名','title2'=>'电话','name1'=>'title','name2'=>'mobile','read'=>true),
		array('type'=>'string_two2','title1'=>'门店','title2'=>'使用','name1'=>'storetitle','name2'=>'kecheng','read'=>true),
		array('type'=>'string_two2','title1'=>'售后群','title2'=>'成交日期','name1'=>'classtitle','name2'=>'baomingday','read'=>true),
		array('type'=>'string_two2','title1'=>'使用原价','title2'=>'实际缴费','name1'=>'kechengprice','name2'=>'baofee','read'=>true),
		array('type'=>'string_two2','title1'=>'总课次','title2'=>'已上课次','name1'=>'keshi','name2'=>'iskeshi','read'=>true),
		array('type'=>'title','title'=>'转门店信息','show'=>array('setstatus'=>1)),
		array('type'=>'title','title'=>'转班信息','show'=>array('setstatus'=>2)),
		array('type'=>'title','title'=>'退学信息','show'=>array('setstatus'=>3)),
		array('type'=>'title','title'=>'退学不退费信息','show'=>array('setstatus'=>4)),
		array('type'=>'title','title'=>'停课信息','show'=>array('setstatus'=>5)),
		array('type'=>'title','title'=>'复课信息','show'=>array('setstatus'=>6)),
		array('type'=>'title','title'=>'休学信息','show'=>array('setstatus'=>7)),
		array('type'=>'title','title'=>'复学信息','show'=>array('setstatus'=>8)),
		array('type'=>'title','title'=>'重修信息','show'=>array('setstatus'=>9)),
		array('type'=>'title','title'=>'结课信息','show'=>array('setstatus'=>10)),
		array('type'=>'tip','title'=>'提交后，将进入审批阶段；需要店长或主管审批之后，才能生效'),
		array('type'=>'select2','title'=>'转门店','title2'=>'售后群','name'=>'tostoreid','name2'=>'toclassid','options'=>'stores','options2'=>'class','show'=>array('setstatus'=>1)),
		array('type'=>'string_two2','title1'=>'剩余课时','title2'=>'课时单价','name1'=>'lastkeshi','name2'=>'onefee'),
		array('type'=>'string_two2','title1'=>'剩余费用','title2'=>'需补费用','name1'=>'lastfee','name2'=>'bufee','show'=>array('setstatus'=>1)),
		array('type'=>'select','title'=>'转售后群','name'=>'toclassid','options'=>'class','show'=>array('setstatus'=>2)),
		array('type'=>'string_two2','title1'=>'剩余费用','title2'=>'实际退费','name1'=>'lastfee','name2'=>'tuifee','show'=>array('setstatus'=>3)),
		array('type'=>'text','name'=>'remark','title'=>'备注'),
		array('type'=>'images','name'=>'images','title'=>'凭证'),
		array('type'=>'string_two2','title1'=>'操作人','title2'=>'操作时间','name1'=>'workername','name2'=>'setday','read'=>true),
	);
	$return['setstatus']=array(
		1=>'转校',
		2=>'转班',
		3=>'退学',
		4=>'退学不退费',
		5=>'停课',
		6=>'复课',
		7=>'休学',
		8=>'复学',
		9=>'重修',
		10=>'结课',
	);
	$stores=pdo_getall('jy_yxw_store',array('uniacid'=>$_SESSION['uniacid'],'id <>'=>$item['storeid'],'type'=>1),array('id','title'),'id');
	foreach($stores as &$sv){
		$sv['class']=pdo_getall('jy_yxw_class',array('uniacid'=>$_SESSION['uniacid'],'storeid'=>$sv['id']),array('id','title'),'id');
	}
	$return['class']=pdo_getall('jy_yxw_class',array('id <>'=>$item['classid'],'uniacid'=>$_SESSION['uniacid'],'storeid'=>$item['storeid']),array('id','title'),'id');
	$return['stores']=$stores;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$return=array();
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_yxw_xuesheng',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		$item['cardno']=pdo_getcolumn('jy_yxw_member',array('id'=>$item['memberid'],'uniacid'=>$_SESSION['uniacid']),'cardno');
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回售后列表'),
		),
		'edit_tab'=>true,
		'edits'=>array(
			array(
				'title'=>'基本信息',
				'list'=>array(
					array('type'=>'string','title'=>'售后姓名','name'=>'title','help'=>''),
					array('type'=>'string','title'=>'售后电话','name'=>'mobile','help'=>''),
					array('type'=>'string','title'=>'紧急联系人电话','name'=>'mobile2','help'=>''),
					array('type'=>'image','title'=>'售后照片','name'=>'logo','help'=>''),
					array('type'=>'text','title'=>'售后描述','name'=>'desc','help'=>''),	
					array('type'=>'string','title'=>'住宿情况','name'=>'zhushu','help'=>''),
					array('type'=>'string','title'=>'身份证号码','name'=>'cardno','help'=>''),
					array('type'=>'switch','title'=>'是否已家访','name'=>'jiafang','isradio'=>1,'help'=>''),
				)
			),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array(
		'title'=>trim($postdata['title']),
		'mobile'=>trim($postdata['mobile']),
		'mobile2'=>trim($postdata['mobile2']),
		'logo'=>trim($postdata['logo']),
		'desc'=>trim($postdata['desc']),
		'zhushu'=>trim($postdata['zhushu']),
		'jiafang'=>trim($postdata['jiafang']),
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_yxw_xuesheng',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		pdo_update('jy_yxw_member',array('cardno'=>$postdata['cardno']),array('id'=>$postdata['memberid'],'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['storeid']=$_SESSION['storeid'];
		pdo_insert('jy_yxw_xuesheng',$data);
	}
	exi('操作成功！','','list');
}
if($_RQ['op']=='export'){
	$filename='candel/'.random(15);
	@mkdir(ROOT_AT.'candel/');
	@mkdir(ROOT_AT.$filename);
	$readme='[温馨提示]：文件分两部分，一个是售后列表，一个是售后档案图片文件夹！';
	file_put_contents(ROOT_AT.$filename.'/readme.txt',$readme);
	//售后列表
	$return['params']=array();
	$params=array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']);
	if($_RQ['status']!='all' && $_RQ['status']){
		$params['status']=intval($_RQ['status']);
	}
	if($_RQ['classid']){
		$params['classid']=intval($_RQ['classid']);
		$return['params']['classid']=$_RQ['classid'];
	}elseif($this->session('classid')){
		$params['classid']=$this->session('classid');
		$return['params']['classid']=$this->session('classid');
	}
	$return['params']['status']=$_RQ['status'];
	if(!empty($_RQ['title'])){
		$params['title like']='%'.$_RQ['title'].'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(!empty($_RQ['mobile'])){
		$params['mobile']=$_RQ['mobile'];
		$return['params']['mobile']=$_RQ['mobile'];
	}
	if($_RQ['ids']){
		$ids=trim($_RQ['ids'],';');
		$ids=explode(';',$ids);
		$params['id']=$ids;
	}
	$list=pdo_getall('jy_yxw_xuesheng',$params,$fields);
	if($list){
		foreach($list as $key=>&$item){
			$item['key']=$key+1;
			$item['status']=$this->xuesheng_status[$item['status']];
			$item['createtime']=date('Y/m/d',$item['createtime']);
			$this->model('xuesheng')->dangandown($item,$filename);
			$member=pdo_get('jy_yxw_member',array('id'=>$item['memberid'],'uniacid'=>$_SESSION['uniacid']));
			$pcd=json_decode($member,true);
			$item=array_merge($member,$item);
			$item['xueli']=$this->xueli_type[$item['xueli']];
			$item['jiguan']=$pcd['province'];
			$item['sex']=$this->sex[$item['sex']];
			$infee_log=pdo_get('jy_yxw_infee_log',array('type'=>1,'memberid'=>$item['memberid'],'uniacid'=>$_SESSION['uniacid']));
			$item['pay_type']=$this->pay_types[$infee_log['pay_type']];
			$item['fee']=$infee_log['fee'];
			$item['bufee']=$infee_log['bufee'];
			$item['worker6']=pdo_getcolumn('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['worker6id']),'title');
			$item['classid']=pdo_getcolumn('jy_yxw_class',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['classid']),'title');
			$kechengid=pdo_getcolumn('jy_yxw_class',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['classid']),'kechengid');
			$item['kechengid']=pdo_getcolumn('jy_yxw_kecheng',array('uniacid'=>$_SESSION['uniacid'],'id'=>$kechengid),'title');
			$item['storeid']=pdo_getcolumn('jy_yxw_store',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['storeid']),'title');
			$kaoqing0=pdo_count('jy_yxw_kaoqing_log',array('type'=>0,'xueshengid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']));
			$kaoqingall=pdo_count('jy_yxw_kaoqing_log',array('xueshengid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']));
			if($kaoqingall){
				$item['kaoqing']=price($kaoqing0/$kaoqingall).'%';
			}
			$item['weiji']=pdo_count('jy_yxw_weiji_log',array('xueshengid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']));
			$item['fenstar']=pdo_getcolumn('jy_yxw_dabian_log',array('xueshengid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']),'fenstar');
			$item['jiafang']=$item['jiafang']?'是':'否';
		}
	}
	$header=array(
		'key'=>'序号',
		'storeid'=>'门店',
		'classid'=>'售后群',
		'kechengid'=>'使用',
		'sn'=>'学籍编号',
		'title'=>'售后姓名',
		'sex'=>'性别',
		'cardno'=>'身份证号',
		'jiguan'=>'籍贯',
		'xueli'=>'学历',
		'school'=>'毕业院校',
		'zhuanye'=>'专业',
		'mobile'=>'联系电话',
		'mobile2'=>'紧急联系电话',
		'createtime'=>'成交进班时间',
		'fee'=>'单费',
		'pay_type'=>'缴费方式',
		'bufee'=>'补助情况',
		'worker6'=>'招生人',
		'zhushu'=>'住宿情况',
		'koubei'=>'口碑信息',
		'jiafang'=>'是否家访',
		'kaoqing'=>'考勤率',
		'weiji'=>'违纪次数',
		'fenstar'=>'平时成绩总评分',
		'status'=>'售后状态',
	);
	model('core/tools')->export2excel($header,$list,'售后列表','',$filename);
	$baoname='售后档案'.random(3);
	cfc('tools')->down_zip(ROOT_AT.$filename,$baoname);
}
if($_RQ['op']=='uppdf01'){
	$id=$_RQ['id'];
	$this->model('uppdf')->dangan($id);
	exit;
}
if($_RQ['op']=='del'){
	exi('不能删除！','error');	
}